const path = require('path');
const webpack = require('webpack');
const cleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: {
    main: './src/index.js',
    vendor: [
      'lodash'
    ]
    // app: './src/index.js',
    // another: './src/another-module.js'
  },
  plugins: [
    new cleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      // title: 'Code Splitting',
      title: 'Caching'
    }),
    // new webpack.optimize.CommonsChunkPlugin({ //已被废除
    //   name: 'common' // 指定公共 bundle 的名称。
    // })
    // new webpack.optimize.CommonsChunkPlugin({
    //     name: 'manifest'
    // })
  ],
  optimization: {
    splitChunks: { //CommonsChunkPlugin已被废除 使用splitChunks代替
      cacheGroups: {
          // commons: {
          //     name: "commons",
          //     chunks: "initial",
          //     minChunks: 2
          // },
          vendor: {
            name: 'vendor'
          },
          manifest: {
              name: "manifest",
              // chunks: "initial",
              // minChunks: 2
          }
      }
  }
  },
  output: {
    // filename: '[name].bundle.js',
    filename: '[name].[chunkhash].js',
    path: path.resolve(__dirname,'dist')
  }
}